const { Sequelize, DataTypes, Model } = require("sequelize");
const sequelize = require("../config/sequelize");

const User = sequelize.define(
  "User",
  {
    // 在这里定义模型属性
    openid: {
      type: DataTypes.STRING,
      allowNull: false,
      comment: "小程序用户唯一标识",
    },
    sessionKey: {
      type: DataTypes.STRING,
      allowNull: false,
      comment: "会话",
    },
    username: {
      type: DataTypes.STRING,
      allowNull: false,
    },
    college: {
      type: DataTypes.STRING,
      allowNull: false,
      defaultValue: "未知大学",
      comment: "所属大学",
    },
    age: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 20,
      comment: "年龄",
    },
    sex: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 1,
      comment: "性别",
    },
    height: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 160,
      comment: "身高",
    },
    weight: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 50,
      comment: "体重",
    },
    targetWeight: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 50,
      comment: "目标体重",
    },
    avatar: {
      type: DataTypes.STRING,
      comment: "头像",
    },
    score: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: "积分",
    },
    concernNum: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: "关注数",
    },
    fansNum: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: "粉丝数",
    },
  },
  {
    // 这是其他模型参数
    sequelize: sequelize,
    tableName: "user",
    underscored: true, //显示在数据库字段为下划线
    paranoid: true, //软删除
  }
);

// (async () => {
//   await sequelize.sync({ alter: true });
// })();

module.exports = User;
